import {createApp} from 'vue'
import type {App} from 'vue'
import {createPinia} from 'pinia'

import ViewUIPlus from 'view-ui-plus'
import mainApp from './App.vue'
import router from './router'
import axios from 'axios'
import VueAxios from 'vue-axios'
import '@/config/axios/config'
import '@/assets/app/main.less'
import components from "./components/components";
import 'view-ui-plus/dist/styles/viewuiplus.css';
import XEUtils from 'xe-utils'
import VXETable from 'vxe-table'
import 'vxe-table/lib/style.css'
import 'md-editor-v3/lib/style.css';
import storage from "@/config/storage";
import {cleanDictCache, isPermission, isRole} from "@/util";

function useTable(app: App) {
    app.use(VXETable)
}

VXETable.setup({
    table: {
        border: true,
        resizable: true,
        autoResize: true,
        showOverflow: true
    },
    grid: {
        proxyConfig: {
            autoLoad: false,
            form: true,
            props: {
                result: 'data',
                total: 'maxIndex'
            },
        },
        toolbarConfig: {
            zoom: true,
            custom: true,
            refresh: true
        }
    }
})

const app = createApp(mainApp)

app.config.globalProperties.$utils = XEUtils
app.config.globalProperties.$webBaseUrl = import.meta.env.VITE_WEB_BASE_URL
app.config.globalProperties.$apiBaseUrl = import.meta.env.VITE_API_BASE_URL
app.config.globalProperties.$fileBaseUrl = import.meta.env.VITE_FILE_BASE_URL
app.config.globalProperties.$isRole = isRole
app.config.globalProperties.$isPermission = isPermission

app.use(useTable)
app.use(createPinia())
app.use(router)
app.use(ViewUIPlus)
app.use(components)
app.use(VueAxios, axios)
app.mount('#app')


window.onbeforeunload = function () {
    storage.removeItem("menus")
    storage.removeItem("pages")
    storage.removeItem("roles")
    storage.removeItem("permissions")
    cleanDictCache()
}



